package qs.openxt.libs.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;
import android.widget.Toast;

public class BaseActivity extends FragmentActivity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	protected BaseStyle customStyle(int viewId, String titleName,
			boolean hasBack) {
		return new BaseStyle(this, viewId, titleName, hasBack, false);
	}

	protected BaseStyle customStyle(int viewId, String titleName,
									boolean hasBack, boolean hasOk) {
		return new BaseStyle(this, viewId, titleName, hasBack, hasOk);
	}

	protected void onDestroy() {
		super.onDestroy();
	}

	protected void toActivity(final Class<?> cls) {
		toActivity(cls, false);
	}

	protected void toActivity(final Class<?> cls, final boolean closeFlag) {
		final Context mContext = this;
		runOnUiThread(new Runnable() {
			public void run() {
				Intent intent = new Intent();
				intent.setClass(mContext, cls);
				startActivity(intent);
				if (closeFlag)
					finish();
			}
		});
	}

	protected void toActivityForResult(Class<?> cls, Bundle bundle,
			int requestCode) {
		Intent intent = new Intent();
		intent.setClass(this, cls);
		if (bundle != null)
			intent.putExtras(bundle);
		startActivityForResult(intent, requestCode);
	}

	protected void toActivity(final Class<?> cls, final Bundle bundle,
			final boolean closeFlag) {
		final Context mContext = this;
		runOnUiThread(new Runnable() {
			public void run() {
				Intent intent = new Intent();
				intent.setClass(mContext, cls);
				if (bundle != null)
					intent.putExtras(bundle);
				startActivity(intent);
				if (closeFlag)
					finish();
			}
		});
	}

	public void showMsg(String msg) {
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}

	public int getWinWidth() {
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		return dm.widthPixels;
	}

	public int getWinHeight() {
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		return dm.heightPixels;
	}
}
